<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/9/25 23:02
 */

namespace module\user\front\input;

use app\library\validate\CaptchaValidate;
use mof\exception\LogicException;
use mof\Request;

class UnbindInput extends BindInput
{

    public static function __make(Request $request): static
    {
        $type = $request->post('type');
        if (static::EMAIL === $type) {
            $rules = [
                'account|邮箱'   => 'require|email',
                'captcha|验证码' => 'require|emsCaptcha:account,#unbind',
            ];
            $message = [
                'account.require'    => '邮箱不能为空',
                'account.email'      => '邮箱格式不正确',
                'captcha.emsCaptcha' => '验证码不正确',
            ];
        } else if (static::MOBILE === $type) {
            $rules = [
                'account|手机号' => 'require|mobile',
                'captcha|验证码' => 'require|smsCaptcha:account,#unbind',
            ];
            $message = [
                'account.require'    => '手机号不能为空',
                'account.email'      => '手机号格式不正确',
                'captcha.smsCaptcha' => '验证码不正确',
            ];
        } else {
            throw new LogicException('未知的解绑类型');
        }

        CaptchaValidate::register();
        $data = $request->withValidate($rules, $message)->post();

        return new self($data);
    }
}